/*
 *http://www.apache.org/licenses/LICENSE-2.0
 *Copyright (c) 2021 fullset
 *@ClassName SysOrgDaoImpl
 *@date 2021/6/29 15:34
 *@author: pangps
 *@Description TODO
 */
package com.fs.orm.dao.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.fs.orm.dao.SysOrgDao;
import com.fs.orm.entity.SysOrg;
import com.fs.orm.mapper.SysOrgMapper;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class SysOrgDaoImpl extends ServiceImpl<SysOrgMapper, SysOrg> implements SysOrgDao {

    @Override
    public boolean addOrg(SysOrg sysOrg) {
        sysOrg.setCreateTime(new Date());
        sysOrg.setUpdateTime(new Date());
        return SqlHelper.retBool(baseMapper.insert(sysOrg));
    }

    @Override
    public boolean logicalDeleteById(String id) {
        SysOrg sysOrg = new SysOrg();
        sysOrg.setIsDeleted(1);
        UpdateWrapper<SysOrg> orgUpdateWrapper = new UpdateWrapper<>();
        orgUpdateWrapper.eq("id", id);
        int update = baseMapper.update(sysOrg, orgUpdateWrapper);
        return update > 0 ? true : false;
    }

    @Override
    public boolean batchDel(String ids) {
        String [] arr = ids.split(",");
        UpdateWrapper<SysOrg> orgUpdateWrapper = new UpdateWrapper<>();
        orgUpdateWrapper.in("id", arr);
        orgUpdateWrapper.set("is_deleted", 1);
        int update = baseMapper.update(null, orgUpdateWrapper);
        return update > 0 ? true : false;
    }

    @Override
    public SysOrg editSysOrg(SysOrg sysOrg) {
        UpdateWrapper<SysOrg> orgUpdateWrapper = new UpdateWrapper<>();
        orgUpdateWrapper.eq("id", sysOrg.getId());
        orgUpdateWrapper.set("user_name", sysOrg.getName());
        baseMapper.update(sysOrg, orgUpdateWrapper);
        return sysOrg;
    }

    @Override
    public List<SysOrg> getList(QueryWrapper qWrapper) {
        return baseMapper.selectList(qWrapper);
    }
}
